const treeify = require('treeify');
const { pair, head, tail, list, isNull } = require('./526');

function print(pair) {
  console.log(treeify.asTree(pair, true));
}
function isPair(x) {
  return (
    Object.prototype.toString.call(x) === '[object Object]' &&
    'head' in x &&
    'tail' in x
  );
}
const m = list(1, 2, 3, 4);
// print(m);

function countLeaves(x) {
  if (isNull(x)) return 0;
  if (!isPair(x)) return 1;
  return countLeaves(head(x)) + countLeaves(tail(x));
}
// console.log(countLeaves(m));

module.exports = {
  isPair,
  print
};
